﻿using Lunar;
using System.Globalization;
namespace AnalyStock.WPFPage;

/// <summary>
///     Page1.xaml 的交互逻辑
/// </summary>
public partial class TitlePage : Page
{
    public TitlePage()
    {
        InitializeComponent();
        //SetCalendar();
        SetCalendar_LunarDll();
    }

    private void SetCalendar_LunarDll()
    {
        var dt = DateTime.Now;
        var solar = new Solar(dt.Year, dt.Month, dt.Day);
        LunarTxt.Text = $"\n{dt:D}\t{solar.Lunar.ShortString}\n";
    }
    private void SetCalendar()
    {
        ChineseLunisolarCalendar cnClnd = new();
        var dt = DateTime.Today; // new DateTime(2020, 12, 15);
        var year = cnClnd.GetYear(dt);
        // 是否有闰月,返回正整数（2020年闰4月，返回值为5）
        var leapMonth = cnClnd.GetLeapMonth(year);
        var month = cnClnd.GetMonth(dt);
        var strMonth = leapMonth == month ? $"闰{month - 1}月" : $"{month}月";
        var day = cnClnd.GetDayOfMonth(dt);
        LunarTxt.Text += $"\n{dt:D}\t农历{strMonth}{day}日";
    }
}